package com.gmail.sabuj.career.qna.core;


public class ColorCodeList extends CircularLinkedList<Character> {

	public void reArrange(char[] pattern){
		Node a = super.head;
		if(null != pattern && pattern.length > 1 ){
			while(a.getValue() != pattern[0])
				a = a.getNext();
			Node c = a;
			Node b = a.getNext();
			for (int i = 0; i < pattern.length; i++) {
				char p = pattern[i];
				if(p == c.getValue().charValue()){
					c = b;
					b = b.getNext();
				} else {
					while(b != a){
						if(b.getValue() == p){
							Node t = c;
							b = c;
							c = t;
							c = c.getNext();
							b = b.getNext();
							break;
						}
						b = b.getNext();
						
					}
				}
			}
		}
	}
	
}
